#ifndef __PID_H
#define __PID_H

#include "stdint-gcc.h"


#define M_OUTMAX    1.0f

#define D_KP        0.32f
#define D_KI        0.4f
#define D_KD        0.0f

#define Q_KP        0.32f
#define Q_KI        0.4f
#define Q_KD        0.0f
#define PID_OUT_MAX             8.0f //max:24/sqr(3)
#define PID_DEAD_ZONE           0.05f
#define PID_INTERG_START_ERROR  1.0f
#define PID_INTERG_MAX_VAL      5.0f


#define FILTER_KP 0.8f

typedef struct
{
    float kp;
    float kd;
    float ki;
    float tar;
    float pre;
    float integral;
    float err_last;
    float err;
    float out;
    float out_max;
    float cycle;
}motor_pid, *p_motor_pid;

void set_pid(p_motor_pid pid, float kp, float ki, float kd, float max);
void pid_ctrl(p_motor_pid pid, float input_now, float tar);

#endif
